home *** CD-ROM | disk | FTP | other *** search
/ ETO Development Tools 4 / ETO Development Tools 4.iso / Tools - Objects / MacApp / MacApp 3.0a2 / Libraries / UEditionDocument.cp < prev    next >
Encoding:
Text File  |  1991-05-01  |  42.1 KB  |  1,474 lines  |  [TEXT/MPS ]

  1. // UEditionDocument.cp 
  2. // Copyright © 1984-1991 by Apple Computer Inc.    All rights reserved.
  3.  
  4. #ifndef __UEDITIONDOCUMENT__
  5. #include <UEditionDocument.h>
  6. #endif
  7.  
  8. #ifndef __UGEOMETRY__
  9. #include <UGeometry.h>
  10. #endif
  11.  
  12. #ifndef __RESOURCES__
  13. #include <Resources.h>
  14. #endif
  15.  
  16. #ifndef __TOOLUTILS__
  17. #include <ToolUtils.h>
  18. #endif
  19.  
  20. #ifndef __PACKAGES__
  21. #include <Packages.h>
  22. #endif
  23.  
  24. #ifndef __ERRORS__
  25. #include <Errors.h>
  26. #endif
  27.  
  28. #ifndef __UFILE__
  29. #include <UFile.h>
  30. #endif
  31.  
  32. #ifndef __USECTION__
  33. #include <USection.h>
  34. #endif
  35.  
  36. #ifndef __UWINDOW__
  37. #include <UWindow.h>
  38. #endif
  39.  
  40. #ifndef __UFILEHANDLER__
  41. #include <UFileHandler.h>
  42. #endif
  43.  
  44. #ifndef __UAPPLICATION__
  45. #include <UApplication.h>
  46. #endif
  47.  
  48. #ifndef __UMACAPPUTILITIES__
  49. #include <UMacAppUtilities.h>
  50. #endif
  51.  
  52. #ifndef __UERRORMGR__
  53. #include <UErrorMgr.h>
  54. #endif
  55.  
  56. #ifndef __UMACAPPGLOBALS__
  57. #include <UMacAppGlobals.h>
  58. #endif
  59.  
  60. #ifndef __UMEMORY__
  61. #include <UMemory.h>
  62. #endif
  63.  
  64. #ifndef __UMENUMGR__
  65. #include <UMenuMgr.h>
  66. #endif
  67.  
  68. const unsigned long kEditionDocRsrcType = 'EdSt';// rsrc type for Edition Doc private rsrc 
  69. const short kEditionDocRsrcID = 301;            // rsrc id for Edition Doc private rsrc 
  70.  
  71. typedef struct EditionDocSettings
  72. {                                                // used for saving settings in a resource 
  73.     Boolean showSectionBorders;
  74.     Boolean stopAllEditions;
  75. }    *EditionDocSettingsPtr, ** EditionDocSettingsHandle;
  76.  
  77. typedef pascal void (*DoToSectionType) (TSection* item, void* staticLink);
  78.  
  79. //--------------------------------------------------------------------------------------------------
  80. #pragma segment MADocumentRes
  81.  
  82. CSectionIterator::CSectionIterator(TEditionDocument* itsDocument,
  83.                            ArrayIndex itsLowBound,
  84.                            ArrayIndex itsHighBound,
  85.                            Boolean itsForward) :
  86.     CObjectIterator(itsDocument ? itsDocument->fSectionList : NULL, itsLowBound, itsHighBound, itsForward)
  87.  
  88. {
  89. }
  90.  
  91. //--------------------------------------------------------------------------------------------------
  92. #pragma segment MADocumentRes
  93.  
  94. CSectionIterator::CSectionIterator(TEditionDocument* itsDocument,
  95.                            Boolean itsForward) :
  96.     CObjectIterator(itsDocument ? itsDocument->fSectionList : NULL, itsForward)
  97. {
  98. }
  99.  
  100. //--------------------------------------------------------------------------------------------------
  101. #pragma segment MADocumentRes
  102.  
  103. CSectionIterator::CSectionIterator(TEditionDocument* itsDocument) :
  104.     CObjectIterator(itsDocument ? itsDocument->fSectionList : NULL)
  105. {
  106. }
  107.  
  108. //--------------------------------------------------------------------------------------------------
  109. #pragma segment MADocumentRes
  110.  
  111. TSection* CSectionIterator::CurrentSection(void)
  112. {
  113.     return (TSection*)this->CurrentObject();
  114. }
  115.  
  116. //--------------------------------------------------------------------------------------------------
  117. #pragma segment MADocumentRes
  118.  
  119. TSection* CSectionIterator::FirstSection(void)
  120. {
  121.     return (TSection*)this->FirstObject();
  122. }
  123.  
  124. //--------------------------------------------------------------------------------------------------
  125. #pragma segment MADocumentRes
  126.  
  127. TSection* CSectionIterator::NextSection(void)
  128. {
  129.     return (TSection*)this->NextObject();
  130. }
  131.  
  132. //--------------------------------------------------------------------------------------------------
  133. #pragma segment MAInit
  134.  
  135. pascal void InitUEditionDocument(void)
  136.  
  137. {
  138.     /* if application NEEDS the edition mgr,
  139.      *  then fail out if it can't load,
  140.      *  else if system HAS the edition mgr,
  141.      *  then continue if we can't get it (and set gConfiguration accordingly). */
  142.  
  143.     if (qNeedsEditionMgr)
  144.         FailOSErr(InitEditionPack());
  145.     else if (gConfiguration.hasEditionMgr)
  146.     {
  147.         OSErr err = InitEditionPack();
  148.         if (err != noErr)
  149.             if (err == editionMgrInitErr)
  150.                 gConfiguration.hasEditionMgr = FALSE;// could not load edition pack 
  151.             else
  152.                 FailOSErr(err);
  153.     }
  154. }
  155.  
  156. //--------------------------------------------------------------------------------------------------
  157. #pragma segment MAOpen
  158.  
  159. pascal void TEditionDocument::Initialize(void)    // override 
  160.  
  161. {
  162.     inherited::Initialize();
  163.  
  164.     fSectionList = NULL;
  165.     fStopAllEditions = FALSE;
  166.     fShowSectionBorders = TRUE;
  167.     fNextEditionNumber = 1;
  168.     fNewPublishers = FALSE;
  169.     fEditionCreator = '????';
  170. }
  171.  
  172. //--------------------------------------------------------------------------------------------------
  173. #pragma segment MAOpen
  174.  
  175. pascal void TEditionDocument::IEditionDocument(TFile* itsFile,
  176.                                                const OSType itsFileType,
  177.                                                const OSType itsCreator,
  178.                                                const OSType itsScrapType,
  179.                                                Boolean usesDataFork,
  180.                                                Boolean usesRsrcFork,
  181.                                                Boolean keepsDataOpen,
  182.                                                Boolean keepsRsrcOpen,
  183.                                                const OSType editionCreator)
  184.  
  185. {
  186.     this->IFileBasedDocument(itsFile, itsFileType, itsCreator, itsScrapType, usesDataFork, usesRsrcFork, keepsDataOpen, keepsRsrcOpen);
  187.  
  188.     fEditionCreator = editionCreator;
  189.  
  190.     fSectionList = NewList();                    // !!! needs failure handler
  191.     if (qDebug)
  192.         fSectionList->SetEltType("TSection");    // takes MAName
  193. }
  194.  
  195. //--------------------------------------------------------------------------------------------------
  196. #pragma segment MAClose
  197.  
  198. pascal void TEditionDocument::Free(void)        // override 
  199.  
  200. {
  201.     fSectionList = (TList *)FreeListIfObject(fSectionList);
  202.  
  203.     inherited::Free();
  204. }
  205.  
  206. //--------------------------------------------------------------------------------------------------
  207. #pragma segment MAClose
  208.  
  209. pascal void TEditionDocument::FreeData(void)    // override 
  210.  
  211. {
  212.     fSectionList->FreeAll();
  213.  
  214.     inherited::FreeData();
  215. }
  216.  
  217. //--------------------------------------------------------------------------------------------------
  218. #pragma segment MADocumentRes
  219.  
  220. pascal Boolean TEditionDocument::CanPublishSelection(void)
  221.  
  222. {
  223.     // ask the target view if it can publish the selection 
  224.     return (FALSE);
  225. }
  226.  
  227. //--------------------------------------------------------------------------------------------------
  228. #pragma segment MADocumentRes
  229.  
  230. pascal Boolean TEditionDocument::CanSubscribe(void)
  231.  
  232. {
  233.     // ask the target view if it can subscribe 
  234.     return (FALSE);
  235. }
  236.  
  237. //--------------------------------------------------------------------------------------------------
  238. #pragma segment MAWriteFile
  239.  
  240. pascal void TEditionDocument::DoWrite(TFile* aFile,
  241.                                       Boolean makingCopy)// override 
  242.  
  243. {
  244.     CSectionIterator iter(this);
  245.     
  246.     // 1. Tell all canceled sections to delete themselves: publishers delete their container file
  247.     // and all section objects remove their section rsrcs from the rsrc fork if any. The routine also
  248.     // removes a section from the document's list of sections and frees the section.
  249.     
  250.     for (TSection* aSection = iter.FirstSection(); iter.More(); aSection = iter.NextSection())
  251.         if (aSection->fCanceled)
  252.         {
  253.             aSection->Delete();
  254.             this->RemoveSection(aSection);
  255.             aSection->Free();
  256.         }
  257.  
  258.     // 2. write out (as a resource) fStopAllEditions and fShowSectionBorders 
  259.     this->DoWriteSettings(aFile);
  260.  
  261.     // 3. tell each section to write itself out 
  262.     for (aSection = iter.FirstSection(); iter.More(); aSection = iter.NextSection())
  263.             aSection->DoWrite(aFile, makingCopy);
  264.  
  265.     // 4. clear the new publishers flag 
  266.     fNewPublishers = FALSE;
  267.  
  268.     inherited::DoWrite(aFile, makingCopy);
  269. }
  270.  
  271. //--------------------------------------------------------------------------------------------------
  272. #pragma segment MAWriteFile
  273.  
  274. pascal void TEditionDocument::DoWriteSettings(TFile*)
  275.  
  276. {
  277.     EditionDocSettingsHandle h = (EditionDocSettingsHandle)NewPermHandle(sizeof(EditionDocSettings));
  278.  
  279.     (*h)->showSectionBorders = fShowSectionBorders;
  280.     (*h)->stopAllEditions = fStopAllEditions;
  281.  
  282.     AddResource((Handle)h, kEditionDocRsrcType, kEditionDocRsrcID, "Edition Doc Settings");
  283.     FailResError();
  284. }
  285.  
  286. //--------------------------------------------------------------------------------------------------
  287. #pragma segment MAReadFile
  288.  
  289. pascal void TEditionDocument::DoRead(TFile* aFile,
  290.                                      Boolean forPrinting)// override 
  291.  
  292. {
  293.     // 1. read in (from a resource) fStopAllEditions and fShowSectionBorders 
  294.     this->DoReadSettings(aFile);
  295.  
  296.     // 2. create the section objects and tell each section to read itself in 
  297.     for (short i = 1; i <= Count1Resources(rSectionType); ++i)
  298.     {
  299.         short theID;
  300.         Handle h;
  301.  
  302.         h = Get1IndResource(rSectionType, i);    // get the resource handle 
  303.         FailNIL((void*)h);
  304.         theID = (short)(*((SectionHandle)h))->sectionID;
  305.         switch ((*((SectionHandle)h))->kind)
  306.         {
  307.             case stPublisher:
  308.                 this->DoReadPublisher(aFile, theID);    // !!! pass in a resource stream
  309.                 break;
  310.             case stSubscriber:
  311.                 this->DoReadSubscriber(aFile, theID);    // !!! pass in a resource stream
  312.                 break;
  313.             default:
  314.                 if (qDebug)
  315.                     ProgramBreak("SectionHandle appears to be corrupt");
  316.                 break;
  317.         }
  318.     }
  319.  
  320.     // 3. read in the rest of the document's data 
  321.     inherited::DoRead(aFile, forPrinting);
  322. }
  323.  
  324. //--------------------------------------------------------------------------------------------------
  325. #pragma segment MAReadFile
  326.  
  327. pascal void TEditionDocument::DoReadSettings(TFile*)
  328.  
  329. {
  330.     Handle h = Get1Resource(kEditionDocRsrcType, kEditionDocRsrcID);
  331.     FailNIL(h);
  332.     fShowSectionBorders = (*((EditionDocSettingsHandle)h))->showSectionBorders;
  333.     fStopAllEditions = (*((EditionDocSettingsHandle)h))->stopAllEditions;
  334.     ReleaseResource(h);
  335. }
  336.  
  337. //--------------------------------------------------------------------------------------------------
  338. #pragma segment MAReadFile
  339.  
  340. pascal void TEditionDocument::DoReadPublisher(TFile* aFile,
  341.                                               short theID)
  342.  
  343. {
  344.     TPublisher * aPublisher = this->DoMakePublisher(NULL, NULL, theID);
  345.     aPublisher->DoRead(aFile);
  346.     this->AddSection(aPublisher);
  347. }
  348.  
  349. //--------------------------------------------------------------------------------------------------
  350. #pragma segment MAReadFile
  351.  
  352. pascal void TEditionDocument::DoReadSubscriber(TFile* aFile,
  353.                                                short theID)
  354.  
  355. {
  356.     TSubscriber * aSubscriber = this->DoMakeSubscriber(NULL, NULL, theID);
  357.     aSubscriber->DoRead(aFile);
  358.     this->AddSection(aSubscriber);
  359. }
  360.  
  361. //--------------------------------------------------------------------------------------------------
  362. #pragma segment MASelCommand
  363.  
  364. pascal void TEditionDocument::DoMenuCommand(CmdNumber aCmdNumber)// override 
  365.  
  366. {
  367.     switch (aCmdNumber)
  368.     {
  369.         case cCreatePublisher:
  370.             this->DoNewPublisher();
  371.             break;
  372.         case cSubscribeTo:
  373.             this->DoNewSubscriber();
  374.             break;
  375.         case cOptions:
  376.             this->DoSectionOptions();
  377.             break;
  378.         case cBorders:
  379.             {
  380.                 TSectionBorderCmd * aSectionBorderCmd = new TSectionBorderCmd;
  381.                 aSectionBorderCmd->ISectionBorderCmd(cBorders, this);
  382.                 this->PostCommand(aSectionBorderCmd);
  383.                 break;
  384.             }
  385.         case cStopAllEditions:
  386.             {
  387.                 TStopAllEditionsCmd * aStopAllEditionsCmd = new TStopAllEditionsCmd;
  388.                 aStopAllEditionsCmd->IStopAllEditionsCmd(cStopAllEditions, this);
  389.                 this->PostCommand(aStopAllEditionsCmd);
  390.                 break;
  391.             }
  392.         default:
  393.             inherited::DoMenuCommand(aCmdNumber);
  394.             break;
  395.     }
  396. }
  397.  
  398. //--------------------------------------------------------------------------------------------------
  399. #pragma segment MADocumentNonRes
  400.  
  401. pascal void TEditionDocument::DoSectionOptions(void)
  402.  
  403. {
  404.     TSection * aSection = this->GetSelectedSection();
  405.     if (aSection != NULL)
  406.     {
  407.         if (aSection->GetSectionType() == stPublisher)
  408.             this->DoPublisherOptions((TPublisher *)aSection);
  409.         else if (aSection->GetSectionType() == stSubscriber)
  410.             this->DoSubscriberOptions((TSubscriber *)aSection);
  411.         else if (qDebug)
  412.             ProgramBreak("what kind of section is it anyway?");
  413.     }
  414. }
  415.  
  416. //--------------------------------------------------------------------------------------------------
  417. #pragma segment MAClose
  418.  
  419. pascal void TEditionDocument::Close(void)        // override 
  420.  
  421. {
  422.     /* preflight the Close for the case in which the document's DATA is unchanged (the change
  423.       count is 0) but there are new publishers in the document */
  424.     if ((this->GetChangeCount() == 0) && fNewPublishers)
  425.     {
  426.         TCommand * lastCommand = NULL;
  427.         short poseResult = this->PoseNewPublishersAlert();
  428.         if (poseResult == cancel)
  429.             Failure(noErr, msgCancelled);
  430.  
  431.         lastCommand = this->GetLastCommand();
  432.         if ((lastCommand != NULL) && (lastCommand->fChangedObject == this))
  433.             this->CommitLastCommand();
  434.  
  435.         switch (poseResult)
  436.         {
  437.             case kYesButton:
  438.                 this->SaveDocument(cClose);        // Will fail if unable to save 
  439.                 break;
  440.             case kNoButton:
  441.                 this->Abandon();
  442.                 break;
  443.         }
  444.     }
  445.  
  446.     inherited::Close();
  447. }
  448.  
  449. //--------------------------------------------------------------------------------------------------
  450. #pragma segment MAClose
  451.  
  452. struct PoseItInfo
  453. {
  454. public:
  455.     PoseItInfo(short itsResult,
  456.                short itsAlertID) :
  457.         result(itsResult),
  458.         alertID(itsAlertID)
  459.     {
  460.     }
  461.  
  462.     short result;
  463.     short alertID;
  464. };
  465.  
  466.  
  467. pascal void PoseIt(void* staticLink)
  468.  
  469. {
  470.     short result = MacAppAlert(((PoseItInfo *)staticLink)->alertID, NULL);
  471.     ((PoseItInfo *)staticLink)->result = result;
  472. }
  473.  
  474.  
  475. pascal short TEditionDocument::PoseNewPublishersAlert(void)
  476.  
  477. {
  478.     short idx;
  479.     Str255 name;
  480.     Str255 reason;
  481.     PoseItInfo info(0, phNewPublisherAlert);
  482.  
  483.     if (gApplication->fAppDone)
  484.         idx = bzQuitting;
  485.     else
  486.         idx = bzClosing;
  487.  
  488.     GetIndString(reason, kIDBuzzString, idx);
  489.     name = fTitle;                                // ParamText can compact heap 
  490.     ParamText(name, reason, "", "");
  491.     WithApplicationResFileDo(PoseIt, &info);
  492.     return info.result;
  493. }
  494.  
  495. //--------------------------------------------------------------------------------------------------
  496. #pragma segment MAClose
  497.  
  498. pascal short TEditionDocument::PoseMultPublishersAlert(TSection* aSection)
  499.  
  500. {
  501.     Str255 name;
  502.     PoseItInfo info(0, phMultPublisherWrn);
  503.  
  504.     aSection->GetEditionName(name);
  505.     ParamText(name, "", "", "");
  506.     WithApplicationResFileDo(PoseIt, &info);
  507.     return info.result;
  508. }
  509.  
  510. //--------------------------------------------------------------------------------------------------
  511. #pragma segment MAClose
  512.  
  513. pascal short TEditionDocument::PoseSavingMultPublishersAlert(TSection* aSection)
  514.  
  515. {
  516.     Str255 name;
  517.     Str255 docName;
  518.     PoseItInfo info(0, phSavingMultPublisherWrn);
  519.  
  520.     aSection->GetEditionName(name);
  521.     docName = fTitle;                            // ParamText can compact heap 
  522.     ParamText(name, docName, "", "");
  523.     WithApplicationResFileDo(PoseIt, &info);
  524.     return info.result;
  525. }
  526.  
  527. //--------------------------------------------------------------------------------------------------
  528. #pragma segment MAClose
  529.  
  530. pascal void TEditionDocument::Abandon(void)        // override 
  531. {
  532.     CSectionIterator iter(this);
  533.     
  534.     for (TSection* aSection = iter.FirstSection(); iter.More(); aSection = iter.NextSection())
  535.         if (aSection->GetSectionType() == stPublisher)
  536.         {
  537.             // if publisher is *new* and it hasn't been saved yet,
  538.             // delete the edition container file 
  539.             if (((TPublisher*)aSection)->fNewSection)
  540.                 ((TPublisher*)aSection)->DeleteEditionFile();
  541.         }
  542.  
  543.     inherited::Abandon();
  544. }
  545.  
  546. //--------------------------------------------------------------------------------------------------
  547. #pragma segment MAWriteFile
  548.  
  549. pascal void TEditionDocument::DoNeedDiskSpace(TFile* itsFile,
  550.                                               long& dataForkBytes,
  551.                                               long& rsrcForkBytes)
  552. {
  553.     inherited::DoNeedDiskSpace(itsFile, dataForkBytes, rsrcForkBytes);
  554.  
  555.     rsrcForkBytes = rsrcForkBytes + sizeof(EditionDocSettings);
  556.  
  557.     CSectionIterator iter(this);
  558.  
  559.     for (TSection* aSection = iter.FirstSection(); iter.More(); aSection = iter.NextSection())
  560.         aSection->DoNeedDiskSpace(dataForkBytes, rsrcForkBytes);
  561. }
  562.  
  563. //--------------------------------------------------------------------------------------------------
  564. #pragma segment MADocumentNonRes
  565.  
  566. pascal void TEditionDocument::DoNewPublisher(void)
  567.  
  568. {
  569.     OSErr err;
  570.     NewPublisherReply reply;
  571.     TDesignator * itsDesignator;
  572.     short newSectionID;
  573.     SectionHandle sectionH;
  574.     TPublisher * aPublisher;
  575.     TFileHandler * aFileHandler;
  576.     FSSpec aFSSpec;
  577.     FSSpecPtr aFSSpecPtr;
  578.  
  579.     // set up the reply record 
  580.     err = GetLastEditionContainerUsed(reply.container);
  581.     if ((err != noErr) && (err != fnfErr))        // allow fnfErr 
  582.         FailOSErr(err);
  583.     this->GetNextEditionName(reply.container.theFile.name);
  584.     reply.usePart = FALSE;                        // always set this to FALSE 
  585.  
  586.     // create the preview 
  587.     itsDesignator = this->GetUserSelection();
  588.     FailNIL(itsDesignator);                        // ??? allow non-designated publishers 
  589.  
  590.     this->DoMakePreview(itsDesignator, reply.previewFormat, reply.preview);
  591.  
  592.     this->DoNewPublisherDialog(reply);                // query the user 
  593.  
  594.     // dispose of the preview 
  595.     if (reply.previewFormat == 'PICT')
  596.         reply.preview = (Handle)DisposeIfPicHandle((PicHandle) reply.preview);
  597.     else if (reply.previewFormat == 'TEXT')
  598.         reply.preview = DisposeIfHandle(reply.preview);
  599.  
  600.     if (!reply.canceled)
  601.     {
  602.         if (!reply.replacing)
  603.             FailOSErr(CreateEditionContainerFile(reply.container.theFile, this->GetEditionCreatorSignature(), reply.container.theFileScript));
  604.         newSectionID = this->GetUniqueSectRsrcID();
  605.  
  606.         aFSSpecPtr = NULL;                        // can pass in NULL to NewSection 
  607.         aFileHandler = this->GetFileHandler();
  608.         if ((aFileHandler != NULL) && (aFileHandler->FileExists()))
  609.         {
  610.             aFileHandler->fFile->GetFileSpec(aFSSpec);
  611.             aFSSpecPtr = &aFSSpec;
  612.         }
  613.         // NewSection calls RegisterSection for us 
  614.         err = NewSection(reply.container, aFSSpecPtr, stPublisher, newSectionID, pumOnSave, sectionH);
  615.         if ((err != noErr) && (err != multiplePublisherWrn) && (err != notThePublisherWrn))
  616.             FailOSErr(err);
  617.  
  618.         // Create the publisher object and publish it to disk 
  619.         if (itsDesignator != NULL)
  620.             itsDesignator = (TDesignator *)itsDesignator->Clone();// publisher owns its designator 
  621.         aPublisher = this->DoMakePublisher(itsDesignator, sectionH, newSectionID);
  622.         this->AddSection(aPublisher);
  623.         aPublisher->Publish();
  624.  
  625.         // let the edition document know that there is a new publisher 
  626.         fNewPublishers = TRUE;
  627.     }
  628. }
  629.  
  630. //--------------------------------------------------------------------------------------------------
  631. #pragma segment MADocumentNonRes
  632.  
  633. pascal void TEditionDocument::DoMakePreview(TDesignator* aDesignator,
  634.                                             FormatType& previewFormat,
  635.                                             Handle& preview)
  636.  
  637. {
  638.     preview = NULL;
  639.     previewFormat = this->GetPublishPreference();
  640.     if ((previewFormat == 'TEXT') || (previewFormat == 'PICT'))
  641.     {
  642.         FailInfo fi;
  643.         THandleStream* aHandleStream = NULL;
  644.         VOLATILE(aHandleStream);                // needed in failure handler
  645.  
  646.         preview = NewPermHandle(0);
  647.         if (fi.Try())
  648.         {
  649.             aHandleStream = new THandleStream;
  650.             aHandleStream->IHandleStream(preview, 6);
  651.             this->DoWriteData(previewFormat, aDesignator, aHandleStream);
  652.             aHandleStream = (THandleStream*)FreeIfObject(aHandleStream);
  653.             fi.Success();
  654.         }
  655.         else    // Recover
  656.         {
  657.             preview = DisposeIfHandle(preview);
  658.             aHandleStream = (THandleStream*)FreeIfObject(aHandleStream);
  659.             fi.ReSignal();
  660.         }
  661.     }
  662. }
  663.  
  664. //--------------------------------------------------------------------------------------------------
  665. #pragma segment MADocumentNonRes
  666.  
  667. pascal OSType TEditionDocument::GetEditionCreatorSignature(void)
  668.  
  669. {
  670.     return fEditionCreator;
  671. }
  672.  
  673. //--------------------------------------------------------------------------------------------------
  674. #pragma segment MADocumentNonRes
  675.  
  676. pascal FormatType TEditionDocument::GetPublishPreference(void)
  677.  
  678. {
  679.     return ((long)'TEXT');                        /* by default, prefer to publish 'TEXT' over 'PICT' */
  680. }
  681.  
  682. //--------------------------------------------------------------------------------------------------
  683. #pragma segment MADocumentNonRes
  684.  
  685. pascal TPublisher* TEditionDocument::DoMakePublisher(TDesignator* itsDesignator,
  686.                                                      SectionHandle itsSectionHandle,
  687.                                                      short itsSectionID)
  688.  
  689. {
  690.     TPublisher * aPublisher = new TPublisher;    // create a TPublisher object 
  691.     aPublisher->IPublisher(this, itsDesignator, itsSectionHandle, itsSectionID);
  692.     return aPublisher;
  693. }
  694.  
  695. //--------------------------------------------------------------------------------------------------
  696. #pragma segment MADocumentNonRes
  697.  
  698. pascal void TEditionDocument::DoNewPublisherDialog(NewPublisherReply& reply)
  699.  
  700. {
  701.     // override this method if you decide to use the NewPublisherExpDialog instead 
  702.     FailOSErr(NewPublisherDialog(reply));
  703. }
  704.  
  705. //--------------------------------------------------------------------------------------------------
  706. #pragma segment MADocumentNonRes
  707.  
  708. pascal void TEditionDocument::DoNewSubscriber(void)
  709.  
  710. {
  711.     OSErr err;
  712.     NewSubscriberReply reply;
  713.     short newSectionID;
  714.     TFileHandler * aFileHandler;
  715.     FSSpec aFSSpec;
  716.     FSSpecPtr aFSSpecPtr;
  717.     SectionHandle sectionH;
  718.     TSubscriber * aSubscriber;
  719.     TDesignator * aDesignator;
  720.  
  721.     err = GetLastEditionContainerUsed(reply.container);// fill in the reply 
  722.     if ((err != noErr) && (err != fnfErr))        // allow fnfErr 
  723.         FailOSErr(err);
  724.     reply.formatsMask = this->GetSubscriberFormatsMask();// set up the formatsMask 
  725.     this->DoNewSubscriberDialog(reply);
  726.     if (!reply.canceled)
  727.     {
  728.         newSectionID = this->GetUniqueSectRsrcID();
  729.         // create a new section handle 
  730.         aFSSpecPtr = NULL;
  731.         aFileHandler = this->GetFileHandler();
  732.         if ((aFileHandler != NULL) && (aFileHandler->FileExists()))
  733.         {
  734.             aFileHandler->fFile->GetFileSpec(aFSSpec);
  735.             aFSSpecPtr = &aFSSpec;
  736.         }
  737.         FailOSErr(NewSection(reply.container, aFSSpecPtr, stSubscriber, newSectionID, sumAutomatic, sectionH));
  738.         // NewSection calls RegisterSection for us 
  739.  
  740.         // create a TDesignator for the TSubscriber object 
  741.         aDesignator = this->GetUserSelection();
  742.         if (aDesignator != NULL)
  743.             aDesignator = (TDesignator *)aDesignator->Clone();// the subscriber owns the designator
  744.  
  745.         // create a TSubscriber object and add it to our list of sections
  746.         aSubscriber = this->DoMakeSubscriber(aDesignator, sectionH, newSectionID);
  747.         this->AddSection(aSubscriber);
  748.         // aSubscriber->Subscribe(); Ed Mgr will send us a SectionEvent telling us to read the section
  749.     }
  750. }
  751.  
  752. //--------------------------------------------------------------------------------------------------
  753. #pragma segment MADocumentNonRes
  754.  
  755. pascal TSubscriber* TEditionDocument::DoMakeSubscriber(TDesignator* itsDesignator,
  756.                                                        SectionHandle itsSectionHandle,
  757.                                                        short itsSectionID)
  758.  
  759. {
  760.     // create and return a TSubscriber object 
  761.     TSubscriber * aSubscriber = new TSubscriber;
  762.     aSubscriber->ISubscriber(this, itsDesignator, itsSectionHandle, itsSectionID);
  763.     return aSubscriber;
  764. }
  765.  
  766. //--------------------------------------------------------------------------------------------------
  767. #pragma segment MADocumentNonRes
  768.  
  769. pascal void TEditionDocument::DoNewSubscriberDialog(NewSubscriberReply& reply)
  770.  
  771. {
  772.     // override this method if you decide to use the NewSubscriberExpDialog instead 
  773.     FailOSErr(NewSubscriberDialog(reply));        // pose the new subscriber dialog 
  774. }
  775.  
  776. //--------------------------------------------------------------------------------------------------
  777. #pragma segment MADocumentNonRes
  778.  
  779. pascal void TEditionDocument::DoPublisherOptions(TPublisher* aPublisher)
  780.  
  781. {
  782.     SectionOptionsReply reply;
  783.  
  784.     reply.sectionH = aPublisher->fSectionHandle;
  785.     this->DoPublisherOptionsDialog(reply);
  786.     if (!reply.canceled)
  787.     {
  788.         if (reply.changed)
  789.             aPublisher->MarkDirty();
  790.  
  791.         if (reply.action == sectionWriteMsgID)
  792.             aPublisher->Publish();
  793.         else if (reply.action == sectionCancelMsgID)
  794.         {
  795.             TCancelPublisherCmd * aCancelPublisherCmd = new TCancelPublisherCmd;
  796.             aCancelPublisherCmd->ICancelPublisherCmd(cCancelPublisher, this, aPublisher);
  797.             this->PostCommand(aCancelPublisherCmd);
  798.         }
  799.     }
  800. }
  801.  
  802. //--------------------------------------------------------------------------------------------------
  803. #pragma segment MADocumentNonRes
  804.  
  805. pascal void TEditionDocument::DoPublisherOptionsDialog(SectionOptionsReply& reply)
  806.  
  807. {
  808.     // override this method if you decide to use the SectionOptionsExpDialog instead 
  809.     FailOSErr(SectionOptionsDialog(reply));        // should it call SectionOptionsExpDialog always???
  810. }
  811.  
  812. //--------------------------------------------------------------------------------------------------
  813. #pragma segment MADocumentNonRes
  814.  
  815. pascal void TEditionDocument::DoSubscriberOptions(TSubscriber* aSubscriber)
  816.  
  817. {
  818.     SectionOptionsReply reply;
  819.  
  820.     reply.sectionH = aSubscriber->fSectionHandle;
  821.     this->DoSubscriberOptionsDialog(reply);
  822.     if (!reply.canceled)
  823.     {
  824.         if (reply.changed)
  825.             aSubscriber->MarkDirty();
  826.  
  827.         if (reply.action == sectionReadMsgID)
  828.             aSubscriber->Subscribe();
  829.         else if (reply.action == 'goto')
  830.             aSubscriber->OpenPublisher();
  831.         else if (reply.action == sectionCancelMsgID)
  832.         {
  833.             TCancelSubscriberCmd * aCancelSubscriberCmd = new TCancelSubscriberCmd;
  834.             aCancelSubscriberCmd->ICancelSubscriberCmd(cCancelSubscriber, this, NULL, aSubscriber);
  835.             this->PostCommand(aCancelSubscriberCmd);
  836.         }
  837.     }
  838. }
  839.  
  840. //--------------------------------------------------------------------------------------------------
  841. #pragma segment MADocumentNonRes
  842.  
  843. pascal void TEditionDocument::DoSubscriberOptionsDialog(SectionOptionsReply& reply)
  844.  
  845. {
  846.     // override this method if you decide to use the SectionOptionsExpDialog instead 
  847.     FailOSErr(SectionOptionsDialog(reply));    // should it call SectionOptionsExpDialog always???
  848. }
  849.  
  850. //--------------------------------------------------------------------------------------------------
  851. #pragma segment MADocumentRes
  852.  
  853. pascal void TEditionDocument::DoSetupMenus(void)// override 
  854.  
  855. {
  856.     inherited::DoSetupMenus();
  857.  
  858.     if (gConfiguration.hasEditionMgr)            /* *always* test to ensure that the Edition
  859.                                                   Mgr was initialized */
  860.     {
  861.         if (fNewPublishers)                        // there are new publishers! 
  862.         {
  863.             Enable(cSave, TRUE);
  864.             Enable(cRevert, TRUE);
  865.         }
  866.  
  867.         Enable(cCreatePublisher, this->CanPublishSelection());
  868.         Enable(cSubscribeTo, this->CanSubscribe());
  869.  
  870.         TSection * aSection = this->GetSelectedSection();
  871.         if (aSection != NULL)
  872.         {
  873.             Enable(cOptions, TRUE);
  874.             if (aSection->GetSectionType() == stPublisher)
  875.                 SetIndCmdName(cOptions, kIDBuzzString, bzPublisherOptions);
  876.             else if (aSection->GetSectionType() == stSubscriber)
  877.                 SetIndCmdName(cOptions, kIDBuzzString, bzSubscriberOptions);
  878.             else if (qDebug)
  879.                 ProgramBreak("what kind of section is it anyway?");
  880.         }
  881.  
  882.         Enable(cBorders, TRUE);
  883.         SetMenuState(cBorders, kIDBuzzString, bzShowBorders, bzHideBorders, fShowSectionBorders);
  884.  
  885.         EnableCheck(cStopAllEditions, TRUE, fStopAllEditions);
  886.     }
  887. }
  888.  
  889. //--------------------------------------------------------------------------------------------------
  890. #pragma segment MADocumentNonRes
  891.  
  892. pascal void TEditionDocument::GetNextEditionName(Str63& editionName)
  893.  
  894. {
  895.     short preInsert;
  896.     short constChars;
  897.     Str255 name(""),  numStr("");
  898.     
  899.     editionName = "";
  900.     GetIndString(name, kIDBuzzString, bzUntitled);
  901.     if (ParseTitleTemplate(name, preInsert, constChars))
  902.     {
  903.         NumToString(fNextEditionNumber, numStr);
  904.         if (SubstituteInTitle(name, numStr, preInsert, constChars))
  905.             ++fNextEditionNumber;
  906.     }
  907.     CopyStr255(name, (Ptr) & editionName);
  908. }
  909.  
  910. //--------------------------------------------------------------------------------------------------
  911. #pragma segment MADocumentNonRes
  912.  
  913. pascal SignedByte TEditionDocument::GetSubscriberFormatsMask(void)
  914.  
  915. {
  916.     /* return a mask corresponding to the edition format type to display within the subscriber
  917.       dialog box as follows:
  918.       GetSubscriberFormatsMask = [kPICTformatMask +] [kTextformatMask +] [ksndFormatMask] */
  919.  
  920.     return (kTEXTformatMask);                    // default return value
  921. }
  922.  
  923. //--------------------------------------------------------------------------------------------------
  924. #pragma segment MADocumentNonRes
  925.  
  926. const short kFirstRsrcID = 1000;
  927. const short kLastRsrcID = 32767;
  928. const short kBitsInArray = kLastRsrcID - kFirstRsrcID;
  929.  
  930. pascal short TEditionDocument::GetUniqueSectRsrcID(void)
  931. {
  932.     short counter = 0;
  933.     Size arraySize = (kBitsInArray / sizeof(Byte)) + 1;
  934.     Ptr aPtr = NewPermPtr(arraySize);
  935.     Boolean foundNewID;
  936.  
  937.     BlockSet(aPtr, arraySize, 0x00);            // zero it out
  938.     
  939.     CSectionIterator iter(this);
  940.  
  941.     for (TSection* aSection = iter.FirstSection(); iter.More(); aSection = iter.NextSection())
  942.     {
  943.         short itsRsrcID = aSection->fRsrcID;
  944.         
  945.         if (itsRsrcID >= kFirstRsrcID)
  946.             BitSet(aPtr, itsRsrcID - kFirstRsrcID);
  947.         else
  948.         {
  949.             if (qDebug)
  950.                 ProgramBreak("problem with section rsrc id");
  951.         }
  952.     }
  953.  
  954.     while (BitTst(aPtr, counter) && (counter < kBitsInArray))
  955.         ++counter;
  956.  
  957.     foundNewID =!BitTst(aPtr, counter);            // see if we got a new rsrc id 
  958.  
  959.     aPtr = DisposeIfPtr(aPtr);                    // dispose of the array 
  960.  
  961.     if (!foundNewID)
  962.         Failure(minErr, 0);
  963.  
  964.     return (counter + kFirstRsrcID);            // return the new sect rsrc id 
  965. }
  966.  
  967. //--------------------------------------------------------------------------------------------------
  968. #pragma segment MADocumentRes
  969.  
  970. pascal Boolean TEditionDocument::IsBorderShown(TSection* aSection)
  971.  
  972. {
  973.     return (fShowSectionBorders || this->IsSectionSelected(aSection));
  974. }
  975.  
  976. //--------------------------------------------------------------------------------------------------
  977. #pragma segment MADocumentNonRes
  978.  
  979. pascal Boolean TEditionDocument::IsSectionSelected(TSection* aSection)
  980.  
  981. {
  982.     TDesignator * userSelection;
  983.  
  984.     if ((aSection != NULL) && (aSection->fDesignator != NULL))
  985.     {
  986.         userSelection = this->GetUserSelection();
  987.         if (userSelection != NULL)
  988.             return (userSelection->IsContained(aSection->fDesignator) != kNotContained);
  989.         else
  990.             return (FALSE);
  991.     }
  992.     else
  993.         return (FALSE);
  994. }
  995.  
  996. //--------------------------------------------------------------------------------------------------
  997. #pragma segment MADocumentNonRes
  998.  
  999. pascal Boolean TEditionDocument::IsAnySectionDirty(void)
  1000. {
  1001.     CSectionIterator iter(this);
  1002.     
  1003.     for (TSection* aSection = iter.FirstSection(); iter.More(); aSection = iter.NextSection())
  1004.         if (aSection->IsDirty())
  1005.             return TRUE;
  1006.     return FALSE;
  1007. }
  1008.  
  1009. //--------------------------------------------------------------------------------------------------
  1010. #pragma segment MADocumentNonRes
  1011.  
  1012. pascal void TEditionDocument::AddSection(TSection* aSection)
  1013.  
  1014. {
  1015.     // Protect against double installation 
  1016.     if (fSectionList)
  1017.     {
  1018.         if (fSectionList->GetIdentityItemNo(aSection) == 0)// doesn't already exist in list 
  1019.             fSectionList->Insert(aSection);
  1020.     }
  1021.     else if (qDebug)
  1022.         ProgramBreak("fSectionList is NULL");
  1023. }
  1024.  
  1025. //--------------------------------------------------------------------------------------------------
  1026. #pragma segment MADocumentNonRes
  1027.  
  1028. pascal void TEditionDocument::RemoveSection(TSection* aSection)
  1029.  
  1030. {
  1031.     if (fSectionList)
  1032.         fSectionList->Delete(aSection);
  1033.     else if (qDebug)
  1034.         ProgramBreak("fSectionList is NULL");
  1035. }
  1036.  
  1037. //--------------------------------------------------------------------------------------------------
  1038. #pragma segment MADocumentNonRes
  1039.  
  1040. pascal void TEditionDocument::CancelSection(TSection* aSection,
  1041.                                             Boolean cancel)
  1042.  
  1043. {
  1044.     aSection->CancelSection(cancel);
  1045. }
  1046.  
  1047. //--------------------------------------------------------------------------------------------------
  1048. #pragma segment MADocumentNonRes
  1049.  
  1050. pascal void TEditionDocument::EachSectionDo(pascal void(* DoToSection)(TSection* aSection,
  1051.                                                                        void* staticLink),
  1052.                                             void* staticLink)
  1053. {
  1054.     if (fSectionList)
  1055.         fSectionList->Each((DoToObjectType)DoToSection, staticLink);
  1056.     else if (qDebug)
  1057.         ProgramBreak("fSectionList is NULL");
  1058. }
  1059.  
  1060. //--------------------------------------------------------------------------------------------------
  1061. #pragma segment MADocumentNonRes
  1062.  
  1063. pascal void TEditionDocument::EachPublisherDo(pascal void(* DoToPublisher)(TPublisher* aPublisher,
  1064.                                                                            void* staticLink),
  1065.                                               void* staticLink)
  1066. {
  1067.     CSectionIterator iter(this);
  1068.     
  1069.     for (TSection* aSection = iter.FirstSection(); iter.More(); aSection = iter.NextSection())
  1070.         if (aSection->GetSectionType() == stPublisher)
  1071.             DoToPublisher((TPublisher *)aSection, staticLink);
  1072. }
  1073.  
  1074. //--------------------------------------------------------------------------------------------------
  1075. #pragma segment MADocumentNonRes
  1076.  
  1077. pascal void TEditionDocument::EachCanceledSectionDo(pascal void(* DoToCanceledSection)(TSection* aSection,
  1078.                                                                                        void* staticLink),
  1079.                                                     void* staticLink)
  1080. {
  1081.     CSectionIterator iter(this);
  1082.     
  1083.     for (TSection* aSection = iter.FirstSection(); iter.More(); aSection = iter.NextSection())
  1084.         if (aSection->fCanceled)
  1085.             DoToCanceledSection(aSection, staticLink);
  1086. }
  1087.  
  1088. //--------------------------------------------------------------------------------------------------
  1089. #pragma segment MADocumentNonRes
  1090.  
  1091. pascal void TEditionDocument::EachSubscriberDo(pascal void(* DoToSubscriber)(TSubscriber* aSubscriber,
  1092.                                                                              void* staticLink),
  1093.                                                void* staticLink)
  1094. {
  1095.     CSectionIterator iter(this);
  1096.     
  1097.     for (TSection* aSection = iter.FirstSection(); iter.More(); aSection = iter.NextSection())
  1098.         if (aSection->GetSectionType() == stSubscriber)
  1099.             DoToSubscriber((TSubscriber *)aSection, staticLink);
  1100. }
  1101.  
  1102. //--------------------------------------------------------------------------------------------------
  1103. #pragma segment MADocumentNonRes
  1104.  
  1105. pascal TSection* TEditionDocument::FirstSectionThat(pascal Boolean(* TestSection)(TSection* aSection,
  1106.                                                                                   void* staticLink),
  1107.                                                     void* staticLink)
  1108. {
  1109.     if (fSectionList)
  1110.         return (TSection *)(fSectionList->FirstThat((TestObjectType)TestSection, staticLink));
  1111.     else
  1112.     {
  1113.         if (qDebug)
  1114.             ProgramBreak("fSectionList is NULL");
  1115.         return (NULL);
  1116.     }
  1117. }
  1118.  
  1119. //--------------------------------------------------------------------------------------------------
  1120. #pragma segment MADocumentNonRes
  1121.  
  1122. pascal TSection* TEditionDocument::GetSectionObject(SectionHandle aSectionHandle)
  1123. {
  1124.     CSectionIterator iter(this);
  1125.     
  1126.     for (TSection* aSection = iter.FirstSection(); iter.More(); aSection = iter.NextSection())
  1127.         if (aSection->fSectionHandle == aSectionHandle)
  1128.             return aSection;
  1129.     return NULL;
  1130. }
  1131.  
  1132. //--------------------------------------------------------------------------------------------------
  1133. #pragma segment MADocumentNonRes
  1134.  
  1135. pascal TSection* TEditionDocument::GetSelectedSection(void)
  1136. {
  1137.     return (NULL);
  1138. }
  1139.  
  1140. //--------------------------------------------------------------------------------------------------
  1141. #pragma segment MAFields
  1142.  
  1143. pascal void TEditionDocument::Fields(TObject* obj)
  1144.  
  1145. {
  1146.     obj->DoToField("TEditionDocument", NULL, bClass);
  1147.     obj->DoToField("fSectionList",  & fSectionList, bObject);
  1148.     obj->DoToField("fStopAllEditions",  & fStopAllEditions, bBoolean);
  1149.     obj->DoToField("fShowSectionBorders",  & fShowSectionBorders, bBoolean);
  1150.     obj->DoToField("fNextEditionNumber",  & fNextEditionNumber, bInteger);
  1151.     obj->DoToField("fNewPublishers",  & fNewPublishers, bBoolean);
  1152.     obj->DoToField("fEditionCreator",  & fEditionCreator, bOSType);
  1153.  
  1154.     inherited::Fields(obj);
  1155. }
  1156.  
  1157. //--------------------------------------------------------------------------------------------------
  1158. #pragma segment MADocumentNonRes
  1159.  
  1160. pascal void TEditionDocument::SetSectionBorders(Boolean state,
  1161.                                                 Boolean invalidate)
  1162. {
  1163.     if (fShowSectionBorders != state)
  1164.     {
  1165.         fShowSectionBorders = state;
  1166.  
  1167.         /* !!! should probably:
  1168.           if (invalidate)
  1169.           this->EachSectionDo(InvalidateSection);    this requires TSection.Invalidate
  1170.         */
  1171.  
  1172.         if (invalidate)
  1173.         {
  1174.             CWindowIterator iter(this);
  1175.         
  1176.             for (TWindow* aWindow = iter.FirstWindow(); iter.More(); aWindow = iter.NextWindow())
  1177.                 aWindow->ForceRedraw();
  1178.         }
  1179.     }
  1180. }
  1181.  
  1182. //--------------------------------------------------------------------------------------------------
  1183. #pragma segment MADocumentRes
  1184.  
  1185. pascal void TEditionDocument::SetStopAllEditions(Boolean state)
  1186. {
  1187.     if (fStopAllEditions != state)
  1188.     {
  1189.         fStopAllEditions = state;
  1190.         if (!state)                                // if turning "off" stop editions 
  1191.         {
  1192.             CSectionIterator iter(this);
  1193.             
  1194.             for (TSection* aSection = iter.FirstSection(); iter.More(); aSection = iter.NextSection())
  1195.                 if (aSection->GetSectionType() == stSubscriber)
  1196.                     ((TSubscriber*)aSection)->SubscribeIfNewer();
  1197.         }
  1198.     }
  1199. }
  1200.  
  1201. //******************************************************************************************
  1202. //       T C a n c e l P u b l i s h e r C m d                                               
  1203. //******************************************************************************************
  1204. #pragma segment MACommandRes
  1205.  
  1206. pascal void TCancelPublisherCmd::ICancelPublisherCmd(CmdNumber itsCmdNumber,
  1207.                                                      TDocument* itsDocument,
  1208.                                                      TPublisher* itsPublisher)
  1209.  
  1210. {
  1211.     this->ICommand(itsCmdNumber, itsDocument, NULL);
  1212.  
  1213.     fPublisher = itsPublisher;
  1214. }
  1215.  
  1216. //--------------------------------------------------------------------------------
  1217. #pragma segment MADoCommand
  1218.  
  1219. pascal void TCancelPublisherCmd::DoIt(void)
  1220.  
  1221. {
  1222.     ((TEditionDocument *)fChangedObject)->CancelSection(fPublisher, kCancel);
  1223. }
  1224.  
  1225. //--------------------------------------------------------------------------------
  1226. #pragma segment MADoCommand
  1227.  
  1228. pascal void TCancelPublisherCmd::UndoIt(void)
  1229.  
  1230. {
  1231.     ((TEditionDocument *)fChangedObject)->CancelSection(fPublisher, kDontCancel);
  1232. }
  1233.  
  1234. //******************************************************************************************
  1235. //       T C a n c e l S u b s c r i b e r C m d                                               
  1236. //******************************************************************************************
  1237. #pragma segment MACommandRes
  1238.  
  1239. pascal void TCancelSubscriberCmd::ICancelSubscriberCmd(CmdNumber itsCmdNumber,
  1240.                                                        TDocument* itsDocument,
  1241.                                                        TView* itsView,
  1242.                                                        TSubscriber* itsSubscriber)
  1243.  
  1244. {
  1245.     this->ICommand(itsCmdNumber, itsDocument, itsView);
  1246.  
  1247.     fSubscriber = itsSubscriber;
  1248. }
  1249.  
  1250. //--------------------------------------------------------------------------------
  1251. #pragma segment MADoCommand
  1252.  
  1253. pascal void TCancelSubscriberCmd::DoIt(void)
  1254.  
  1255. {
  1256.     ((TEditionDocument *)fChangedObject)->CancelSection(fSubscriber, kCancel);
  1257. }
  1258.  
  1259. //--------------------------------------------------------------------------------
  1260. #pragma segment MADoCommand
  1261.  
  1262. pascal void TCancelSubscriberCmd::UndoIt(void)
  1263.  
  1264. {
  1265.     ((TEditionDocument *)fChangedObject)->CancelSection(fSubscriber, kDontCancel);
  1266. }
  1267.  
  1268. //******************************************************************************************
  1269. //       T S e c t i o n B o r d e r C m d                                                   
  1270. //******************************************************************************************
  1271. #pragma segment MACommandRes
  1272.  
  1273. pascal void TSectionBorderCmd::ISectionBorderCmd(CmdNumber itsCmdNumber,
  1274.                                                  TDocument* itsDocument)
  1275.  
  1276. {
  1277.     this->ICommand(itsCmdNumber, itsDocument, NULL);
  1278.  
  1279.     fShowSectionBorders =!((TEditionDocument *)fChangedObject)->fShowSectionBorders;
  1280. }
  1281.  
  1282. //--------------------------------------------------------------------------------
  1283. #pragma segment MADoCommand
  1284.  
  1285. pascal void TSectionBorderCmd::DoIt(void)
  1286.  
  1287. {
  1288.     ((TEditionDocument *)fChangedObject)->SetSectionBorders(fShowSectionBorders, kInvalidate);
  1289. }
  1290.  
  1291. //--------------------------------------------------------------------------------
  1292. #pragma segment MADoCommand
  1293.  
  1294. pascal void TSectionBorderCmd::RedoIt(void)
  1295.  
  1296. {
  1297.     this->DoIt();
  1298. }
  1299.  
  1300. //--------------------------------------------------------------------------------
  1301. #pragma segment MADoCommand
  1302.  
  1303. pascal void TSectionBorderCmd::UndoIt(void)
  1304.  
  1305. {
  1306.     ((TEditionDocument *)fChangedObject)->SetSectionBorders(!fShowSectionBorders, kInvalidate);
  1307. }
  1308.  
  1309. //******************************************************************************************
  1310. //       T S t o p A l l E d i t i o n s C m d                                               
  1311. //******************************************************************************************
  1312. #pragma segment MACommandRes
  1313.  
  1314. pascal void TStopAllEditionsCmd::IStopAllEditionsCmd(CmdNumber itsCmdNumber,
  1315.                                                      TDocument* itsDocument)
  1316.  
  1317. {
  1318.     this->ICommand(itsCmdNumber, itsDocument, NULL);
  1319.  
  1320.     fStopAllEditions =!((TEditionDocument *)fChangedObject)->fStopAllEditions;
  1321. }
  1322.  
  1323. //--------------------------------------------------------------------------------
  1324. #pragma segment MADoCommand
  1325.  
  1326. pascal void TStopAllEditionsCmd::DoIt(void)
  1327.  
  1328. {
  1329.     ((TEditionDocument *)fChangedObject)->SetStopAllEditions(fStopAllEditions);
  1330. }
  1331.  
  1332. //--------------------------------------------------------------------------------
  1333. #pragma segment MADoCommand
  1334.  
  1335. pascal void TStopAllEditionsCmd::RedoIt(void)
  1336.  
  1337. {
  1338.     this->DoIt();
  1339. }
  1340.  
  1341. //--------------------------------------------------------------------------------
  1342. #pragma segment MADoCommand
  1343.  
  1344. pascal void TStopAllEditionsCmd::UndoIt(void)
  1345.  
  1346. {
  1347.     ((TEditionDocument *)fChangedObject)->SetStopAllEditions(!fStopAllEditions);
  1348. }
  1349.  
  1350. //--------------------------------------------------------------------------------------------------
  1351. #pragma segment ANonRes
  1352.  
  1353. pascal void TSectionAdorner::Initialize(void)    // override 
  1354.  
  1355. {
  1356.     inherited::Initialize();
  1357.  
  1358.     fSection = NULL;
  1359.     fBorderRgn = NULL;
  1360. }
  1361.  
  1362. //--------------------------------------------------------------------------------------------------
  1363. #pragma segment ANonRes
  1364.  
  1365. pascal void TSectionAdorner::ISectionAdorner(IDType itsID,
  1366.                                                TSection* itsSection,
  1367.                                              RgnHandle itsBorderRgn)
  1368.  
  1369. {
  1370.     this->IAdorner(itsID,kFreeOnDeletion);
  1371.  
  1372.     fSection = itsSection;
  1373.     fBorderRgn = itsBorderRgn;
  1374. }
  1375.  
  1376. //--------------------------------------------------------------------------------------------------
  1377. #pragma segment ARes
  1378.  
  1379. pascal void TSectionAdorner::Free(void)            // override 
  1380.  
  1381. {
  1382.     fBorderRgn = DisposeIfRgnHandle(fBorderRgn);
  1383.  
  1384.     inherited::Free();
  1385. }
  1386.  
  1387. //--------------------------------------------------------------------------------------------------
  1388. #pragma segment ARes
  1389.  
  1390. pascal void TSectionAdorner::InvalidateAdorner(TView* itsView)    // override 
  1391.  
  1392. {
  1393.     if ((itsView) && (fBorderRgn != NULL))
  1394.         itsView->InvalidateRgn(fBorderRgn);
  1395. }
  1396.  
  1397. //--------------------------------------------------------------------------------------------------
  1398. #pragma segment ARes
  1399.  
  1400. pascal void TSectionAdorner::DrawBorder(const Pattern& whichPattern)
  1401.  
  1402. {
  1403.     // Don't use FillRgn since it ignores the penMode. 
  1404.     PenNormal();
  1405.     PenMode(patXor);
  1406.     PenSize(3, 3);
  1407.     PenPat(whichPattern);
  1408.     FrameRect((*fBorderRgn)->rgnBBox);            // be careful...
  1409. }
  1410.  
  1411. //--------------------------------------------------------------------------------------------------
  1412. #pragma segment ANonRes
  1413.  
  1414. pascal void TSubscriberAdorner::ISubscriberAdorner(IDType itsID,
  1415.                                                       TSubscriber* itsSubscriber,
  1416.                                                    RgnHandle itsBorderRgn)
  1417.  
  1418. {
  1419.     this->ISectionAdorner(itsID, itsSubscriber, itsBorderRgn);
  1420. }
  1421.  
  1422. //--------------------------------------------------------------------------------------------------
  1423. #pragma segment ARes
  1424.  
  1425. pascal void TSubscriberAdorner::DoHighlightSelection(TView* itsView,
  1426.                                                      const VRect& ,
  1427.                                                      HLState fromHL,
  1428.                                                      HLState toHL)// override 
  1429.  
  1430. {
  1431.     if (itsView)
  1432.     {
  1433.         TEditionDocument * itsDocument = (TEditionDocument *)itsView->fDocument;
  1434.         if ((itsDocument != NULL) && (itsDocument->IsBorderShown(fSection)))
  1435.             if ((fromHL == hlOn) && ((toHL == hlDim) || (toHL == hlOff)))
  1436.                 this->DrawBorder(qd.dkGray);            // turning off 
  1437.             else if (((fromHL == hlOff) || (fromHL == hlDim)) && (toHL == hlOn))
  1438.                 this->DrawBorder(qd.dkGray);            // turning on 
  1439.     }
  1440. }
  1441.  
  1442. //--------------------------------------------------------------------------------------------------
  1443. #pragma segment ANonRes
  1444.  
  1445. pascal void TPublisherAdorner::IPublisherAdorner(IDType itsID,
  1446.                                                     TPublisher* itsPublisher,
  1447.                                                  RgnHandle itsBorderRgn)
  1448.  
  1449. {
  1450.     this->ISectionAdorner(itsID, itsPublisher, itsBorderRgn);
  1451. }
  1452.  
  1453. //--------------------------------------------------------------------------------------------------
  1454. #pragma segment ARes
  1455.  
  1456. pascal void TPublisherAdorner::DoHighlightSelection(TView* itsView,
  1457.                                                     const VRect& ,
  1458.                                                     HLState fromHL,
  1459.                                                     HLState toHL)// override 
  1460.  
  1461. {
  1462.     if (itsView)
  1463.     {
  1464.         TEditionDocument * itsDocument = (TEditionDocument *)itsView->fDocument;
  1465.         if ((itsDocument != NULL) && (itsDocument->IsBorderShown(fSection)))
  1466.             if ((fromHL == hlOn) && ((toHL == hlDim) || (toHL == hlOff)))
  1467.                 this->DrawBorder(qd.gray);            // turning off 
  1468.             else if (((fromHL == hlOff) || (fromHL == hlDim)) && (toHL == hlOn))
  1469.                 this->DrawBorder(qd.gray);            // turning on 
  1470.     }
  1471. }
  1472.  
  1473.  
  1474.